<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        canvas{
            border: 1px solid black;
            margin: 0 auto;
            display: block;
        }
    </style>
</head>
<body>
    <canvas width="400px" height="500px" id="myCanvas">
       
    </canvas>    
    <!-- 画布的起始点是左上角（0,0） -->
    <script>
        //获取画布
        //获取画笔
        var paint = myCanvas.getContext('2d');
        //填充矩形
        // paint.fillStyle = 'red'; 
        // // paint.fillRect(0,0,100,300);
        // paint.strokeStyle = 'blue';
        // paint.lineWidth = 20;
        // paint.strokeRect(0,0,100,100);
        //第二种写法
        paint.fillStyle = 'red';
        paint.rect(0,0,100,100);
        paint.fill();
        //
        paint.rect(200,200,100,100);
        paint.strokeStyle = 'pink';
        paint.stroke();
       
        //橡皮擦
        paint.clearRect(50,20,100,50);


    </script>
</body>
</html>